import { MainService } from './main.service';
import { Body, Controller, Post } from '@nestjs/common';
import { LoginDto, RegisterDto } from './dto';
import { ResultData } from 'src/common/utils/result';

@Controller('/')
export class MainController {
  constructor(private readonly mainService: MainService) {}
  @Post('/login')
  async login(@Body() user: LoginDto) {
    const token = await this.mainService.login(user);
    return ResultData.ok({ token }, '登录成功');
  }

  @Post('/register')
  async register(@Body() user: RegisterDto) {
    const res = await this.mainService.register(user);
    return ResultData.ok(res, '注册成功');
  }
}
